import java.awt.event.ActionEvent

import javax.swing.JButton

class Sheet12 {

}

object Sheet12 extends App {
  val result1 = Array(3.14, 1.42, 2.0).map(scala.math.ceil)
  println(result1.mkString(", "))

  val ceil: Double => Double = scala.math.ceil
  val charAt: (String, Int) => Char = _.charAt(_)

  printChar("AAA", _.charAt(_))
  printChar("AAA", charAt)

  val result2 = valueAtOneQuarter(scala.math.ceil)
  println(result2)

  var counter = 0
  val exit = (event: ActionEvent) => if (counter > 9) System.exit(0)
  val button = new JButton("Increment")
  button.addActionListener(exit(_))

  val a = Array("Hello", "World")
  val b: Seq[String] = Array("hello", "world")
  val result3 = a.corresponds(b)(_.equalsIgnoreCase(_))
  println(result3)

  def printChar(input: String, op: (String, Int) => Char): Unit = {
    println(op(input, 0))
  }

  def valueAtOneQuarter(f: Double => Double): Double = f(0.25)

  def mulBy(factor: Double): Double => Double = (x: Double) => factor * x

  def until(condition: => Boolean)(block: => Unit) {
    if (!condition) {
      block
      until(condition)(block)
    }
  }

  def indexOf(str: String, ch: Char): Int = {
    var i = 0
    until (i == str.length) {
      if (str(i) == ch) return i
      i += 1
    }
    -1
  }
}